package com.bsoft.gol.hcs.utils;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.*;

/**
 * @author tongtp
 * @version v0.1
 * @description 线程池工具类
 * @create 2019-05-28 14:42
 **/
public class ThreadPoolExecutorUtil {

	private final static int CORE_POOL_SIZE = 8;

	private final static int MAXIMUM_POOL_SIZE = 16;

	private final static long KEEP_ALIVE_TIME = 3 * 60;

	private final static TimeUnit TIME_UNIT = TimeUnit.SECONDS;

	private final static BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>();

	private final static ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("Thread-pool-%d")
			.build();

	private static ExecutorService threadPoolExecutor = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE,
			KEEP_ALIVE_TIME, TIME_UNIT,
			workQueue, nameThreadFactory, new ThreadPoolExecutor.AbortPolicy());

	public static ExecutorService getThreadPoolExecutor() {
		return threadPoolExecutor;
	}
}
